import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        token: localStorage.getItem("token"),
        isLogin: localStorage.getItem("isLogin"),
        username: localStorage.getItem("username"),
        uid: localStorage.getItem("uid"),
        // BASEURL: "http://10.133.161.9:8081"
    //    "https://1dfd07a6-3001-4272-b5d2-b45d3363e483.mock.pstmn.io"
    //    "http://10.133.161.9:8081"
    },
    mutations: {
        changeLoginState(state, data) {
            state.isLogin = data.isLogin;
            state.username = data.username;
            state.uid = data.uid;
            state.token = data.token;
            if (state.isLogin === true) {
                //    保存
                localStorage.setItem("token", data.token);
                localStorage.setItem("username", data.username);
                localStorage.setItem("uid", data.uid);
                localStorage.setItem("isLogin", true)
            }else{
            //    移除
                localStorage.removeItem("token");
                localStorage.removeItem("username");
                localStorage.removeItem("uid");
                localStorage.removeItem("isLogin");
            }
        }
    }
})

export default store